package com.calm.cdemo.myview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Create by Calm
 * 2020/4/30 16:34
 */
public class DrawBaseView extends View {
    private Paint mPaint;
    public DrawBaseView(Context context) {
        super(context);
    }

    public DrawBaseView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }
    private void init(Context context){
        mPaint = new Paint();
        //设置画笔颜色
        mPaint.setColor(Color.RED);
        //设置填充样式
        //FILL 填充内部
        //FILL_AND_STROKE 内部及边缘 与FILL一致
        //STROKE 仅描边
        mPaint.setStyle(Paint.Style.FILL);
        //设置画笔宽度
        mPaint.setStrokeWidth(2);
        //设置阴影
        //mPaint.setShadowLayer(10,15,15,Color.GREEN);
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawDemo(canvas);
    }

    private void drawDemo(Canvas canvas){
        //画线
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(5);
        //startX 开始X坐标 startY 开始Y坐标 stopX 结束X坐标 stopY 结束Y坐标
        canvas.drawLine(10,10,500,50,mPaint);
        //矩形
        RectF rectF = new RectF(10,60,500,130);
        canvas.drawRect(rectF,mPaint);
        //圆角矩形
        RectF rectF1 = new RectF(10,140,500,220);
        //rx rx 圆角的x y半径
        canvas.drawRoundRect(rectF1,20,20,mPaint);
        //画圆
        //cx 圆心x cy 圆心y radius 圆半径
        canvas.drawCircle(300,330,100,mPaint);
        //画椭圆
        RectF rectF2 = new RectF(10,440,500,540);
        canvas.drawOval(rectF2,mPaint);
        //画狐
        RectF rectF3 = new RectF(10,550,500,650);
        //oval 生成椭圆的矩形  startAngle 狐开始的角度 以X轴正方形为0度
        //sweepAngle 狐持续的角度
        //usCenter 狐是否有两边 ture 有 false 只有一条狐线
        canvas.drawArc(rectF3,0,90,false,mPaint);
    }
}
